home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / misc / getpatch < prev    next >
Text File  |  1996-11-17  |  3KB  |  108 lines

  1. #!/bin/sh
  2. #
  3. # $Id: getpatch,v 2.0 1996/01/15 06:07:04 hamilton Exp hamilton $
  4. #
  5. #
  6. # getpatch written by Jon Hamilton (hamilton@mixcom.com) in a fit of
  7. # boredom.  A crude hack, but it works.
  8. #
  9. # This will check to see which version of the kernel you are running, and
  10. # get all the patches between there and the current release.  If you're
  11. # not running linux, or if you want to specify some other "current version",
  12. # you can say so on the command line, e.g.  ``getpatch 1.3.51'' will cause
  13. # it to behave as if you are currently running 1.3.51.
  14. #
  15. # $PATCH_FTPDIR can be set if you don't like the default location, which
  16. # is ~/kernel_patches.  The script will make sure that you don't already
  17. # have a patch before ftping it.
  18. #
  19. # Be careful; there's not much error checking in this script.  Use at
  20. # your own risk, etc.
  21. #
  22. # There are also some limitations, namely in the way $GETLIST is built, but
  23. # it works for most "sane" uses.
  24. #
  25. # You may do with this as you like, but please leave the attribution and
  26. # the instructional comments above in anything you modify or distribute.
  27.  
  28.  
  29. PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin
  30. # You'll need to change this if you're after the 1.2.x kernels (or 1.5.x, when
  31. # those come out)
  32.  
  33. MAJORVER=1.3
  34.  
  35. # Might be good net.citizenship to change these to reflect a mirror, too.
  36.  
  37. KERNELHOST=ftp.cs.helsinki.fi
  38. KERNELDIR=/pub/Software/Linux/Kernel/v$MAJORVER
  39.  
  40. PATCH_FTPDIR=${PATCH_FTPDIR:-$HOME/kernel-patches}
  41. TMPFILE=$PATCH_FTPDIR/data
  42. export KERNELHOST KERNELDIR TMPFILE PATH PATCH_FTPDIR
  43.  
  44. ftpget(){
  45.   cd $PATCH_FTPDIR
  46.   echo "getting $* => $PATCH_FTPDIR"
  47.   ftp -n $KERNELHOST << DONE
  48.   user anonymous $USER@`hostname`
  49.   cd $KERNELDIR
  50.   prompt
  51.   mget $*
  52. DONE
  53. }
  54.  
  55. get_current_release(){
  56. ftp -n $KERNELHOST > $TMPFILE <<CEASE_ALREADY
  57. user anonymous $USER@`hostname`
  58. cd $KERNELDIR
  59. dir
  60. CEASE_ALREADY
  61.  
  62. CURRENT_RELEASE=`grep LATEST-IS $TMPFILE | awk '{print $9}' | cut -c11-`
  63. echo $CURRENT_RELEASE
  64. }
  65.  
  66. if [ ! -d $PATCH_FTPDIR ] ; then
  67.   mkdir $PATCH_FTPDIR || {
  68.     echo "can't mkdir $PATCH_FTPDIR?!"
  69.     exit 1
  70.   }
  71. fi
  72.  
  73. if [ -n "$1" ] ; then
  74.   CURRENT_VERSION=$1
  75. elif [ "`uname -s`" = "Linux" ] ; then
  76.   CURRENT_VERSION=`uname -r`
  77. else
  78.   echo "You're not running linux on this machine; please specify"
  79.   echo "which kernel version you have on the command line."
  80.   exit 1
  81. fi
  82.  
  83. CURRENT_RELEASE=`get_current_release`
  84. echo "Current release is $CURRENT_RELEASE, you're running $CURRENT_VERSION."
  85.  
  86. if [ "$CURRENT_RELEASE" != "$CURRENT_VERSION" ] ; then
  87. # build a list of which patches we need to get
  88. # start with the current release and work backwards
  89.   if [ ! -f "$PATCH_FTPDIR/patch-$CURRENT_RELEASE.gz" ] ; then
  90.     GETLIST=patch-$CURRENT_RELEASE.gz
  91.   else
  92.     unset GETLIST # might as well be paranoid
  93.   fi
  94.   SUCKED_MINOR=`echo $CURRENT_RELEASE | cut -c5-`
  95.   HAVE_MINOR=`echo $CURRENT_VERSION | cut -c5-`
  96.   while [ "$HAVE_MINOR" -ne "$SUCKED_MINOR" ] ; do
  97.     SUCKED_MINOR=`expr $SUCKED_MINOR - 1`
  98.     if [ ! -f $PATCH_FTPDIR/patch-$MAJORVER.$SUCKED_MINOR.gz ] ; then
  99.       GETLIST="$GETLIST patch-$MAJORVER.$SUCKED_MINOR.gz"
  100.     fi
  101.   done
  102.   if [ -z "$GETLIST" ] ; then
  103.     echo "You already have all the patches up to $CURRENT_RELEASE."
  104.   else
  105.     ftpget $GETLIST
  106.   fi
  107. fi
  108.